package logic

import (
	"context"

	"go-zero-service/common/tool"
	"go-zero-service/service/user/api/internal/svc"
	"go-zero-service/service/user/api/internal/types"
	"go-zero-service/service/user/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.RegisterReply, err error) {
	// todo: add your logic here and delete this line
	user := model.User{
		Mobile:   req.Mobile,
		Password: req.Password,
		Uuid:     tool.Uuid(),
		Username: "zhangsan",
	}
	result := l.svcCtx.UserModel.Create(&user)

	return &types.RegisterReply{
		Status: true,
	}, result.Error
}
